package com.lfp.controller;

import com.lfp.config.rabbitmq.DirectExchangeQueueConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @Author lfp
 * @Date 2022/3/29 22:48
 * @Version 1.0
 */
@Slf4j
@RestController
@Api(tags = "普通队列消息")
@RequestMapping("/produce")
public class ProducerController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ApiOperation("消费者发送消息")
    @PostMapping("/sendMessage/{message}")
    public void sendMessage(@PathVariable String message){

        //通过ConfirmConfig.CONFIRM_EXCHANGE_NAME 交换机，使用路由键“key1”发信息
        rabbitTemplate.convertAndSend(DirectExchangeQueueConfig.DIRECT_EXCHANGE_NAME,
                DirectExchangeQueueConfig.DIRECT_ROUTING_KEY,message.getBytes());

        log.info("消息已发送，内容为：{}",message);
    }
}
